package entertainmentguide.entity;

import java.util.StringTokenizer;
/**
 *
 * 
 */
public class Rating {
    private int userId;
    private int restId;
    private int averageRate;
    private int qualityRate;
    private int pricesRate;
    private int serviceRate;

    public Rating(int userId, int restId, int qualityRate, int pricesRate, int serviceRate) {
        this.userId = userId;
        this.restId = restId;
        this.qualityRate = qualityRate;
        this.pricesRate = pricesRate;
        this.serviceRate = serviceRate;
        this.averageRate = (qualityRate+pricesRate+serviceRate)/3;
    }
    public Rating(int userId, int restId, int averageRate, int qualityRate, int pricesRate, int serviceRate) {
        this.userId = userId;
        this.restId = restId;
        this.qualityRate = qualityRate;
        this.pricesRate = pricesRate;
        this.serviceRate = serviceRate;
        this.averageRate = averageRate;
    }
    

    public Rating() {
        
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public int getUserId() {
        return userId;
    }

    public void setRestId(int restId) {
        this.restId = restId;
    }

    public int getRestId() {
        return restId;
    }

    public void setAverageRate(int averageRate) {  // ΠΡΕΠΕΙ ΝΑ ΤΟ ΚΑΝΟΥΜΕ ΝΑ ΥΠΟΛΟΓΙΖΕΙ ΤΟ Μ.Ο.
        this.averageRate = averageRate;
    }

    public int getAverageRate() {
        return averageRate;
    }

    public void setQualityRate(int qualityRate) {  // ΣΕ ΟΛΕΣ ΤΙΣ ΑΞΙΟΛΟΓΗΣΕΙΣ ΠΡΕΠΕΙ ΝΑ ΔΕΧΕΤΑΙ ΤΙΜΕΣ ΜΟΝΟ ΑΠΟ ΤΟ 1 ΕΩΣ ΤΟ 1Ο
        this.qualityRate = qualityRate;
    }

    public int getQualityRate() {
        return qualityRate;
    }

    public void setPricesRate(int pricesRate) {
        this.pricesRate = pricesRate;
    }

    public int getPricesRate() {
        return pricesRate;
    }

    public void setServiceRate(int serviceRate) {
        this.serviceRate = serviceRate;
    }

    public int getServiceRate() {
        return serviceRate;
    }

    @Override
    public String toString(){
        return  "\n" + " | " + "UserID: " + getUserId() + " | " +
                "RestID: " + getRestId() + " | " +
                "Μέσος Όρος: " + getAverageRate() + " | " +
                "Ποιότητα: " + getQualityRate() + " | " +
                "Τιμές: " + getPricesRate() + " | " +
                "Εξυπηρέτηση: " + getServiceRate() + " | ";
    }

    /**
     * Creates a Rating object by parsing line.
     * The line must be in the following format:
     * RATING: <userId> <restId> <averageRate> <qualityRate> <pricesRate> <serviceRate>
     *
     * @param line
     * @return
     */
    public static Rating parseRating(String line) throws IllegalArgumentException{
        StringTokenizer strTok = new StringTokenizer(line);
        String s1 = strTok.nextToken(); // Rating:
        String s2 = strTok.nextToken(); // userId
        String s3 = strTok.nextToken(); // restId
        String s4 = strTok.nextToken(); // averageRate
        String s5 = strTok.nextToken(); // qualityRate
        String s6 = strTok.nextToken(); // pricesRate
        String s7 = strTok.nextToken(); // serviceRate
        strTok.nextToken("\""); //Skip the first toker with "

        int d2 = Integer.parseInt(s2);
        int d3 = Integer.parseInt(s3);
        int d4 = Integer.parseInt(s4);
        int d5 = Integer.parseInt(s5);
        int d6 = Integer.parseInt(s6);
        int d7 = Integer.parseInt(s7);

        return new Rating(d2,d3,d4,d5,d6,d7);
    }

}
